package com.biz.primus.ms.auth.init;

import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.model.sso.auth.vo.GrantedAuthority;
import com.biz.primus.model.sso.auth.vo.MenuGroupVO;
import com.biz.primus.model.sso.auth.vo.MenuItemVO;
import com.biz.primus.model.sso.auth.vo.ResourceVO;
import com.biz.primus.ms.auth.config.AuthConfig;
import com.biz.primus.ms.auth.dao.po.User;
import com.biz.primus.ms.auth.service.UserService;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.google.common.collect.Lists.newArrayList;

/**
 * Created by defei on 9/19/17.
 */
@Service
public class InitManager {

    private final UserService userService;

    private final AuthConfig authConfig;

    @Autowired
    public InitManager(UserService userService, AuthConfig authConfig) {
        this.userService = userService;
        this.authConfig = authConfig;
    }


    @PostConstruct
    public void setup() {
        User superAdmin = userService.getUserResVoById(authConfig.getServiceAuthorityConfig().getDefaultSuperAdminId());
        if(superAdmin == null) {
            User defaultUser = new User();
            defaultUser.setDescription("默认超级管理员");
            defaultUser.setStatus(CommonStatus.ENABLE);
            defaultUser.setUserUnionId(authConfig.getServiceAuthorityConfig().getDefaultSuperAdminId());
            userService.createUser(defaultUser);
        }
    }
}
